<?php

class GalactusViewGallery extends GalactusViewPost {

	function __construct($control) {
		parent::__construct($control);
	}

	public function retrieveCSS( ) {
		return '
			.content-area li:nth-child(6n + 7) {
				margin-left: 0px !important;
			}
		';
	}

	public function retrieveJS( ) {
		return '
		';
	}

	public function show($user_id = NULL) {
		echo '
			<div class="container-fluid">
				<div class="row-fluid">
					<div class="content-area span12">'.$this->retrieveGallery($user_id).'</div>
				</div>
			</div>
			<script type="text/javascript"></script>
		';
	}

	public function retrieveCarousel( ) {
		$gallery = $this->control->model->retrieveContent( );
		$carousel_items = '';
		for($i = 0; $i < count($gallery); ++$i) {
			$date = new DateTime($gallery[$i]["created_on"]);
			$carousel_items .= '
				<div class="item" content-id="'.$gallery[$i]['id'].'">
					<img src="data:image/jpg;base64,'.base64_encode($gallery[$i]["file"]).'" />
					<div class="carousel-caption">
						<h4 class="pull-right">'.$date->format("d/m/Y H:i:s").'</h4>
						<p>RA/DEC:'.$gallery[$i]["right_ascention"].'/'.$gallery[$i]["declination"].'</p>
						<p>AZ/ALT:'.$gallery[$i]["azimuth"].'/'.$gallery[$i]["altitude"].'</p>
					</div>
				</div>
			';
		}
		$body = '
			<div class="carousel" id="carousel">
				<ol class="carousel-indicators"></ol>
				<div class="carousel-inner">'.$carousel_items.'</div>
				<a class="carousel-control left" href="#carousel" data-slide="prev">&lsaquo;</a>
				<a class="carousel-control right" href="#carousel" data-slide="next">&rsaquo;</a>
			</div>
		';
		$footer = '
			<a class="btn btn-small" galactus-command="GALLERY/DOWNLOAD" title="Download do atual conteúdo"><i class="icon-download"></i></a>
			<a class="btn btn-small" galactus-command="GALLERY/REMOVE_CONTENT" title="Remove o atual conteúdo"><i class="icon-remove-circle"></i></a>
		';
		return $this->helper->modal("modal-content", '<span id="logo-galactus">GALACTUS</span>', $body, $footer);
	}

	public function retrieveGallery($user_id = NULL) {
		$gallery = $this->control->model->retrieveContent(NULL, $user_id);
		if(empty($gallery))
			return '
				<div class="alert span12">
					<button type="button" class="close" data-dismiss="alert">&times;</button>
					<strong>Galeria:</strong> Nenhum conteúdo disponível!
				</div>
			';
		$content = "";
		for($i = 0; $i < count($gallery); ++$i) {
			$date = new DateTime($gallery[$i]["created_on"]);
			$content .= '
				<li class="span2" content-id="'.$gallery[$i]["id"].'">
					<a galactus-command="GALLERY/EXPAND_CONTENT" class="thumbnail">
						<img src="data:image/jpg;base64,'.base64_encode($gallery[$i]["file"]).'" />
					</a>
				</li>
			';			
		}
		return '<ul class="thumbnails">'.$content.'</ul>';
	}

}
?>
